package routers

import (
	"github.com/gin-gonic/gin"
	"net/http"
	"personnel-management/controllers"
)

func SetupRouter() *gin.Engine {
	r := gin.Default()
	v1 := r.Group("/back/v1")
	v1.GET("/ping", func(c *gin.Context) {
		c.String(http.StatusOK, "I'll love you till I die")
	})
	v1.POST("/signup", controllers.SignUpHandler)
	v1.POST("/login", controllers.LoginHandler)
	v1.GET("/refresh_token", controllers.RefreshTokenHandler)

	//登录使用
	v1.Use(controllers.JWTAuthMiddleware())
	{
		//看当前个人信息
		v1.GET("/user_message", controllers.UserMessage)
		//修改当前个人信息
		v1.POST("/user_message/:userid", controllers.UpdateUserMessage)
		//加权限
		v1.POST("/add_casbin/:userid", controllers.AddCasbin)
	}
	v2 := r.Group("/users/v1")
	v2.Use(controllers.JWTAuthMiddleware(), controllers.AuthCheckRole())
	{
		v2.GET("/user_list", controllers.UserList)
		v2.POST("/user_delete", controllers.DeleteUser)
	}

	r.NoRoute(func(c *gin.Context) {
		c.JSON(http.StatusOK, gin.H{
			"msg": "404",
		})
	})
	return r
}
